<!DOCTYPE html>
<html lang="zh">
  <head>
    <title>松果网</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link href="http://cdnjs.bootcss.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">
	<link href="http://cdnjs.bootcss.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap-responsive.min.css" rel="stylesheet">
	<link href="css/main.css" rel="stylesheet">
  </head>
  <body>
	<div class="container">
	  <div class="well">
		<form id="signup" class="form-horizontal" method="post" action="#">
		  <legend>注册</legend>
		  <div class="control-group">
			<div class="controls">
			  <div class="input-prepend">
				<span class="add-on"><i class="icon-user"></i></span> 
				<input type="text" id="username" class="input-xlarge" name="username" placeholder="用户名">
			  </div>
			</div>
		  </div>
		  <div class="control-group">
			<div class="controls">
			  <div class="input-prepend">
				<span class="add-on"><i class="icon-envelope"></i></span> 
				<input type="text" id="email" class="input-xlarge" name="email" placeholder="电子邮件">
			  </div>
			</div>
		  </div>
		  <div class="control-group">
			<div class="controls">
			  <div class="input-prepend">
				<span class="add-on"><i class="icon-lock"></i></span> 
				<input type="password" id="password" class="input-xlarge" name="password" placeholder="密码">
			  </div>
			</div>
		  </div>
		  <div class="control-group">
			<div class="controls">
			  <div class="input-prepend">
				<span class="add-on"><i class="icon-lock"></i></span> 
				<input type="password" class="input-xlarge" name="conpassword" placeholder="确认密码">
			  </div>
			</div>
		  </div>
		  <div class="control-group">
			<div class="controls">
			  <button type="submit" class="btn btn-success">提交</button>
			  <a type="button" href="index.html" class="btn btn-success">返回</a>
			</div>
		  </div>
		</form>
	  </div>
	</div>
	<script src="http://cdnjs.bootcss.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="http://cdnjs.bootcss.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>  
	<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
	<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js"></script>
	<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/localization/messages_zh.js"></script>
	<script src="js/localization/messages_zh.js"></script>
	<script type="text/javascript">
		
		$(document).ready(function() {
		
			$("#signup").validate({
				rules : {
					username : {
						required : true,
						alphanumeric : true,
						remote : "/rest/m/user/search/names"
					},
					email : {
						required : true,
						email : true,
						remote : "/rest/m/user/search/emails"
					},
					password : {
						required : true
					},
					conpassword : {
						required : true,
						equalTo : "#password"
					}
				},
				submitHandler : function() {  
					var data = "{\"name\":\""+$("#username").val()+"\",";
					data += " \"email\":\""+$("#email").val()+"\",";
					data += " \"password\":\""+$("#password").val()+"\"}";
					$.ajax({
				    	type : "POST",
				    	url : "/rest/m/user",
				    	contentType : "application/json; charset=utf-8",
				    	data : data,
				    	success : function() {
				    		window.location = "/login.html";
				    	}
					});
		        }
			});
		
		});
	
	</script>
  </body>
</html>
